package com.qqtop10.manager.utils;

import java.io.File;

/**
 * 
 * @author Jovi-林兆维
 * @date 2015年11月4日
 * @version 1.0
 *
 */
public class FolderPath {

	private final static String WINDODSROOT = "D:\\";
	private final static String LINUXROOT = "/usr/";
	private final static String PROJECTROOT = "top10" + File.separator
			+ "default" + File.separator;

	private final static String MPROJECTROOT = "top10" + File.separator
			+ "mobile" + File.separator;

	public static String getRootPath() {
		String os = System.getProperty("os.name").toLowerCase();
		String path = "";
		if (os.indexOf("windows") > -1) {
			path = WINDODSROOT + PROJECTROOT;
		} else {
			path = LINUXROOT + PROJECTROOT;
		}
		return path;
	}

	public static String getMRootPath() {
		String os = System.getProperty("os.name").toLowerCase();
		String path = "";
		if (os.indexOf("windows") > -1) {
			path = WINDODSROOT + MPROJECTROOT;
		} else {
			path = LINUXROOT + MPROJECTROOT;
		}
		return path;
	}

	/**
	 * 获取展示图片保存路径
	 * 
	 * @return
	 */
	public static String getShowPirtruePath() {
		String path = getRootPath() + "images" + File.separator + "show"
				+ File.separator;
		mkdirs(path);
		return path;
	}

	/**
	 * 获取商品图片保存路径
	 * 
	 * @return
	 */
	public static String getGoodsPirtruePath() {
		String path = getRootPath() + "images" + File.separator + "goods"
				+ File.separator;
		mkdirs(path);
		return path;
	}

	/**
	 * 获取模板路径
	 * 
	 * @return
	 */
	public static String getTemplatePath() {
		String path = getRootPath() + "template" + File.separator;
		mkdirs(path);
		return path;
	}

	/**
	 * 获取保存商品页面路径
	 * 
	 * @return
	 */
	public static String getGoodsPath() {
		String path = getRootPath() + "goods" + File.separator;
		mkdirs(path);
		return path;
	}

	/**
	 * 获取js路径
	 * 
	 * @return
	 */
	public static String getJSPath() {
		String path = getRootPath() + "js" + File.separator;
		mkdirs(path);
		return path;
	}

	/**
	 * 如果目录不存在则创建
	 * 
	 * @param path
	 */
	private static void mkdirs(String path) {
		File file = new File(path);
		if (!file.exists()) {
			file.mkdirs();
		}
	}
}
